{literal}
<script type="text/javascript">
    $(document).ready(function(){
        $("#form_usuario").validate({
            rules: {
                nome: { required: true },
                perfil: { required: true },
                email: { required: true },
                login: { required: true },
                senha2: { equalTo: '#senha'},
                senha: { required: true },
                senha2: { required: true, equalTo: '#senha' }
            },
            messages: {
                nome: {required: "Obrigatorio"},
                perfil: {required: "Obrigatorio"},
                email: {required: "Obrigatorio"},
                login: {required: "Obrigatorio"},
                senha: {required: "Obrigatorio"},
                senha2: {required: "Obrigatorio", equalTo:"Senha nao confere"}
            },
            submitHandler: function(form) {
            	$("#perfil").attr("disabled", false);
				jqAjaxForm(form, "div_mensagem");
			}
        });
        
        populaSelect("perfil", "{/literal}{$_site.url}{literal}", "perfil/select-perfil?cod={/literal}{$usuario->perfil_id}{literal}");

        $("#cod_cliente").autocomplete("contrato/complete-codigo", {
    		width: 400,
    		max: 10,
    		scroll: false,
    		scrollHeight: 500,
    		mustMatch:true,
    		delay:400,
    		formatItem: function(data, i, n, value) {
    			return value.split("::")[0]+" - "+value.split("::")[1];
    		},
    		formatResult: function(data, value) {
    			return value.split("::")[0];
    		}
    	});

    	$("#cod_cliente").result(function(event, data, formatted) {
    		if (data) {
    			$("#contrato_id").val(formatted.split("::")[0]);
    			$("#nome_cliente").val(formatted.split("::")[1]);
    		}
    	});

		//AUTO COMPLETE COM O NOME DE CLIENTES
    	$("#nome_cliente").autocomplete("contrato/complete-nome", {
    		width: 400,
    		max: 10,
    		scroll: false,
    		scrollHeight: 500,
    		mustMatch:true,
    		delay:400,
    		formatItem: function(data2, i2, n2, value2) {
				return value2.split("::")[0]+"  (Contrato: "+value2.split("::")[1]+")";
    		},
    		formatResult: function(data2, value2) {
    			return value2.split("::")[0];
				 
    		}
    	});

    	$("#nome_cliente").result(function(event2, data2, formatted2) {
    		if (data2){
    			$("#contrato_id").val(formatted2.split("::")[1]);
    			$("#cod_cliente").val(formatted2.split("::")[1]);
    		}
    	});

    	if("{/literal}{$usuarioPerfil}{literal}" != "{/literal}{$perfis.administrador}{literal}" && "{/literal}{$usuario->id}{literal}" != ""){
    		$("#perfil").attr("disabled", true);
    	}
        
    }); //fecha $(
</script>
{/literal}
    <form id="form_usuario" name="form_usuario" method="post" action="{$_site.url}{$acao}">
    
    
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="mvTituloFundo">
				  <tr>
					<td>
					{if $usuario->id > 0}Editar{else}Novo{/if} Usu&aacute;rio
					<input type="hidden" name="cod" value="{$usuario->id}"/>
					</td>
				  </tr>
				</table>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">                
                <tr>
                  <td class="contForm">
                  
                  <table width="100%" border="0" cellspacing="3" cellpadding="0">
                      <tr>
                        <td width="30%" valign="top" class="fundoTituloForm">Nome:</td>
                        <td class="bordaFormResp">
                        	<input type="text" name="nome" id="nome" class="formulario tamanhoForm" value="{$usuario->vhr_nome}">
                        </td>
                      </tr>
                      <tr>
                        <td width="30%" valign="top" class="fundoTituloForm">Perfil:</td>
                        <td class="bordaFormResp"><select id='perfil' name='perfil'></select></td>
                      </tr>
                      <tr>
                        <td valign="top" class="fundoTituloForm">Email:</td>
                        <td width="70%" class="bordaFormResp"><input name="email" type="text" class="formulario tamanhoForm" id="email" maxlength="60" value="{$usuario->vhr_email}" /></td>
                      </tr>
                      <tr>
                        <td valign="top" class="fundoTituloForm">Login:</td>
                        <td width="70%" class="bordaFormResp"><input name="login" type="text" class="formulario tamanhoForm" id="login" maxlength="50" value="{$usuario->vhr_login}" /></td>
                      </tr>
                      <tr>
                        <td valign="top" class="fundoTituloForm">Senha:</td>
                        <td width="70%" class="bordaFormResp"><input name="senha" type="password" class="formulario tamanhoForm" id="senha" maxlength="50"  value="{$usuario->vhr_senha}" /></td>
                      </tr>
                      <tr>
                        <td valign="top" class="fundoTituloForm">Repita a senha:</td>
                        <td width="70%" class="bordaFormResp"><input name="senha2" type="password" class="formulario tamanhoForm" id="senha2" maxlength="50"  value="{$usuario->vhr_senha}" /></td>
                      </tr>
                      <tr>
                   	  	<td class="fundoTituloForm">Cliente</td>
	                    <td>
		                   	<table width="100%">
		                    	<tr>
		                       		<td valign="top" class="bordaFormResp" width="20%">C&oacute;digo:</td>
		                       		<td valign="top" class="bordaFormResp" width="80%">Nome:</td>
						 		</tr>
						 		<tr>
		                       		<td valign="top" class="bordaFormResp"><input name="cod_cliente" type="text" class="formulario" id="cod_cliente" value="{$contrato->id}" size="10"/>
		                       		<br><input type="hidden" name="contrato_id" id="contrato_id" value="{$contrato->id}"/>
		                       		</td>
		                       		<td valign="top" class="bordaFormResp"><input name="nome_cliente" type="text" class="formulario tamanhoForm" id="nome_cliente" value="{$contrato->vhr_nome}" size="40"/></td>
								</tr>
		               		</table>
		               		<input type="hidden" name="usuariocontrato_id" id="usuariocontrato_id" value="{$usuariocontrato->id}"/>
	                    </td>
	 		 		</tr>
                  </table>
                  
                  </td>
                </tr>
        		<tr>
                  <td class="paddingTop15 paddingBottom15" align="center"><!-- === Botões ( Salvar e Limpar ) === -->
                      <span class="paddingRight15">
                      	<input type="submit" value="Salvar" class="botao">
                      </span>
                    <span class="paddingRight15">
                    <input name="limpar" type="reset" id="Limpar" value="Limpar" class="botao" />
                    </span>
                    <input type="button" value="Cancelar" onclick="cancelar(); return false;" class="botao">
                      <!-- Final === Botões ( Salvar e Limpar ) === -->                      </td>
                </tr>
              </table>	
    </form>
